package com.example.zhangxin.comevedio.activity.fragment;

import android.support.v4.app.Fragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by ZhangXin on 2016/9/13.
 */

public class FragmentFactory {
    private static Map<Integer,BaseFragment> mFragments = new HashMap<>();
    private static Map<Integer,BaseFragment> mFragmentMap = new HashMap<>();
    public static Fragment createFragment(int position){
        BaseFragment mFragment = null;
        mFragment = mFragments.get(position);
        if(mFragment==null){
            switch (position){
                case 0:
                    mFragment = new HomeFragment();
                    break;
                case 1:
                    mFragment = new TalentFragment();
                    break;
                case 2:
                    mFragment = new VideoFragment();
                    break;
                case 3:
                    mFragment = new InteractFragment();
                    break;
                case 4:
                    mFragment = new LoveFragment();
                    break;
            }
            if(mFragment!=null){
                mFragments.put(position,mFragment);
            }
        }
        return mFragment;
    }
    public static Fragment getFragment(int position){
        BaseFragment mFragment = null;
        mFragment = mFragmentMap.get(position);
        if(mFragment==null){
            switch (position){
                case 0:
                    mFragment = new FocusFragment();
                    break;
                case 1:
                    mFragment = new PopularFragment();
                    break;
                case 2:
                    mFragment = new UptodataFragment();
                    break;
            }
            if(mFragment!=null){
                mFragmentMap.put(position,mFragment);
            }
        }
        return mFragment;
    }
}
